import numpy as np
import unittest
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.QtCore import QRect
from PyQt5.QtCore import Qt
from matplotlib.backends.backend_qtagg import FigureCanvas
from matplotlib.figure import Figure
import sys
class TestPlotStatic(unittest.TestCase):

    def setUp(self):
        self.app = QApplication([])
        self.window = QMainWindow()

    def test_plot_static(self):
        figure = Figure(figsize=(10, 10))
        canvas1 = FigureCanvas(figure)
        canvas1.setGeometry(QRect(190, 350, 220, 200))
        _static_ax = canvas1.figure.subplots()
        t = np.linspace(0, 10, 501)
        _static_ax.plot(t, np.tan(t), ".")
        canvas1.setObjectName("canvas1")

        self.window.setGeometry(QRect(0, 0, 600, 600))
        self.window.setCentralWidget(canvas1)
        self.window.show()

        self.assertEqual(canvas1.objectName(), "canvas1")

    def tearDown(self):
        self.window.close()
        del self.app

if __name__ == '__main__':
    qapp = QApplication.instance()
    if not qapp:
        qapp = QApplication(sys.argv)

    app = TestPlotStatic()
    app.show()
    qapp.exec()